<template>
  <div class="box">
    <div class="head">
      <p>提现页面</p>
    </div>
    <el-form ref="form" :model="form" label-width="70px" style="width: 100%;text-align: left;">
      <el-form-item label="提现金额">
        <el-input v-model="form.je"></el-input>可提现金额：{{head.user_balance}}
      </el-form-item>
      <el-form-item label="提现类型">
        <el-radio-group v-model="form.type">
          <el-radio label="支付宝"></el-radio>
          <el-radio label="微信" style="margin-left: 10px;"></el-radio>
          <el-radio label="银行卡" style="margin-left: 10px;"></el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="提现账号">
        <el-input v-model="form.zh"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="upinfo()">立即保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import qs from "qs"
import store from '@/vuex/store'
export default {
  name: 'App',
  data(){
    return{
        uid : this.$store.state.userid,
        form:{
          je:'',
          type:'',
          zh:''
        },
        head:{}
    }
      
  },
  methods:{
    getinfo:function(){
      this.$http.post("/index.php/user/item/itemOrder",qs.stringify({
              // mobile:this.tel,
              // password:this.pwd
                  uid: this.$store.state.userid

              }))
              .then(res => {
                console.log(res)
                this.head = res.data.data
              })
              .catch(error => {
                alert("网络错误")
              });
    },
    upinfo:function(){
      if(this.form.je>this.head.user_balance){
        this.$toast({
          message: '提现金额不能大于可提现金额',
          iconClass: 'icon iconfont icon-cuowu'
        });
      }else if(this.form.je<this.head.min_cash){
        this.$toast({
          message: '提现金额不能小于最小提现金额',
          iconClass: 'icon iconfont icon-cuowu'
        });
      }else if(this.form.type==''){
        this.$toast({
          message: '提现类型不能为空',
          iconClass: 'icon iconfont icon-cuowu'
        });
      }else if(this.form.zh==''){
        this.$toast({
          message: '提现账号不能为空',
          iconClass: 'icon iconfont icon-cuowu'
        });
      }else{
        console.log(this.form)
        this.$http.post("/index.php/user/cash/apply_cash",qs.stringify({
              // mobile:this.tel,
              // password:this.pwd
                  user_id: this.$store.state.userid,
                  amount: this.form.je,
                  account_number: this.form.zh,
                  account_number_type: this.form.type

              }))
              .then(res => {
                console.log(res)
                if(res.data.code == 1){
                  
                  this.$messagebox.confirm(res.data.meg,'提示',{
                    confirmButtonText:'确定'
                  }).then(() => {
                        
                  }).catch(() => {
                                
                  });
                }
              })
              .catch(error => {
                alert("网络错误")
              });
      }
    }
  },
  components:{
    
  },
  created(){
    this.getinfo()
  }
}
</script>

<style scoped lang="less">
.box{
  padding: 0 .2rem;
  .head{
    width: 100%;
    height: 46px;
    box-sizing: border-box;
    border: 1px solid #d6d6d6;
    line-height: 44px;
    margin-bottom: 20px;
    margin-top: 20px;
    p{
    }
  }
}
</style>
